package services

import (
	"github.com/kataras/iris"
	"github.com/siaoynli/goProject/models"
)

type AdminLoginService struct {
	UserName string `form:"username" json:"username" binding:"required,min=5,max=30"`
	Password string `form:"password" json:"password" binding:"required,min=8,max=40"`
}

// Login 用户登录函数
func (service *AdminLoginService) Login() (models.Admin, iris.Map) {
	var admin models.Admin

	if err := models.DB.Where("user_name = ?", service.UserName).First(&admin).Error; err != nil {
		return admin, iris.Map{
			"status": 403,
			"msg":    "账号或密码错误",
		}
	}

	if admin.CheckPassword(service.Password) == false {
		return admin, iris.Map{
			"status": 403,
			"msg":    "账号或密码错误",
		}
	}
	return admin, nil
}



